<template>
  <div class="main_content">

    <div class="bg-purple">
      <div class="b_name">接口名称：{{testName}}</div>
      <div class="b_url">接口地址： '/alarm/fight'</div>
      <div class="b_test">
        <el-button type="primary"  style=" width: 80%" @click="getTest">测试</el-button>
      </div>

    </div>
  </div>
</template>

<script>
  import api from  '../../api/api.js';
  import { request } from '../../api/utils.js'


  export default {
    name: "abnormalVoice",
    data(){
      return{
        testName:'',
        testUrl:''
      }
    },
    created(){
      this.testName=api.fight_name;
      this.testUrl=api.fight;
    },
    mounted(){

    },
    methods:{
      getTest: function(){
        const loading = this.$loading({
          lock: true,
          text: '测试中，请等待',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        var that = this;
        request(this.testUrl,'post',{
          "ip":"192.168.0.1", //ip地址
          "startTime":"2020-10-09 20:44:33",
          "duration":"2020-10-09 20:44:33"
        }).then(res =>{
            loading.close();
            if(res.data.code === 200){
              this.$alert('接口名称:'+that.testName+'； '+'服务器返回消息：'+res.data.message, '测试成功', {
                confirmButtonText: '确定',
                callback: action => {
                }
              });
            }else{
              this.$alert('接口名称:'+that.testName+'； '+'服务器返回错误消息：'+res.data.message, '测试失败', {
                confirmButtonText: '确定',
                callback: action => {
                }
              });
            }}, error => {
            loading.close();
          if(error){
            this.$alert('接口名称:'+that.testName+'； '+error, '测试失败', {
              confirmButtonText: '确定',
              callback: action => {
              }
            });
          }else{
            this.$alert('接口网络不通，请确认接口地址是否正确，接口地址：'+that.testUrl, '测试失败', {
              confirmButtonText: '确定',
              callback: action => {
              }
            });
          }
          }
        )
      }
    }
  }
</script>

<style scoped>
  .main_content{
    height: 100%;
    width: 850px;
  }

  .bg-purple {
    margin-bottom: 30px;
    background: #d3dce6;
    border-radius: 4px;
    min-height: 50px;
    width: 90%;
  }

  .b_name {
    float: left;
    width: 20%;
    margin-top: 10px;
    font-size: 14px;
  }
  .b_url{
    float: left;
    width: 500px;
    margin-top: 10px;
    font-size: 14px;

  }
  .b_test{
    float: left;
    width: 12%;
    margin-top: 5px;
  }
</style>

